const Router = require('koa-router');
const router = new Router();
router.prefix('/excel');
const getExcelData = require('../config/http');
const excelUtil = require('../config/createExcel');
const options = require('../const')
router
    .post('/', async ctx => {
        try {
            const { datas } = await getExcelData(options.jsonData)
            const arr = [];
            Object.keys(datas.sheetMap).forEach(key => {
                arr.push({ 
                    data: excelUtil.makeSheetData(datas.sheetMap[key], options.dataArr[key].format), 
                    name: options.dataArr[key].name 
                })
            })
            const res = excelUtil.create(arr);
            ctx.body = res;
        } catch (error) {
            ctx.body = error;
        }
    })


module.exports = router;